import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import parse from '@dfeidao/atom-web/dt/parse';
import format from '@dfeidao/atom-web/dt/format';
import p001 from './p001';
import render from '@dfeidao/atom-web/render/render';
import p003 from './p003';
import p002 from './p002';
import p004 from './p004';
interface Par extends Event {
	page_no: number;
}
export default async function a011(fd: IFeidaoAiBrowserComponent,e:Par) {
	// todo
	const start1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="start"]').value;
	const end1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="end"]').value;
	let start = 1000;
	if (start1 !== "") {
		 start = parse(start1);
	}
	let end = 10000000000000000000;
	if (end1 !== "") {
		end = parse(end1);
	}
	const stime=start;
	const etime=end;
	if (stime > etime) {
		alert("错误的时间范围");
	}
	const examination_category = fd.data.node.querySelector<HTMLSelectElement>('[data-id="examination_category"]').value;
	const exam_name = fd.data.node.querySelector<HTMLInputElement>('[data-id="exam_name"]').value;
	if (!stime && !etime && !examination_category && !exam_name) {
		const ret = await nodejs<{dt1: Array<{exam_name: string;start_time: number;
			examination_category: string;exam_time: string;exam_score: string;
			finish_time: number}>,t: number}>('examination-management/zj-000001/s001',
			{filter:{page_no:1}});
		const ren = ret.dt1.map((n) => {
			return {...n,start_time:format(n.start_time,2),finish_time:format(n.finish_time,2)};
		});
		render(fd,ren,p001,'p001','inner');
		if (ret.t > 20) {
			render(fd,ret.t,p003,'p003','inner');
		}
		return;
	} else if (!stime && !etime ) {
		alert("必须指定统计的起始日期和终止日期");
		return;
	} else {
	const res= await nodejs<{res: Array<{exam_name: string;start_time: number;examination_category: string;exam_time: string;exam_score: string;finish_time: number}>;red: Array<{}>}>('examination-management/zj-000001/s002',{
		exam_name,
		start_time:stime,
		finish_time:etime,
		examination_category,
		pnge_no:e.page_no
	});
	// console.log(res);
	const ren = res.res.map((n) => {
		return {...n,start_time:format(n.start_time,2),finish_time:format(n.finish_time,2)};
	});

 if (ren.length === 0) {
render(fd,'',p002,'p002',"inner");
} else {
render(fd,ren,p001,'p001','inner');
}
}
}
